home *** CD-ROM | disk | FTP | other *** search
- #ifndef _DArray_h_
- #define _DArray_h_
-
- template <class T>
- class DArray
- {
- public:
- DArray()
- {
- _a = NULL;
- _size = 0;
- }
-
- DArray(UInt32 size)
- {
- _a = NULL;
- _size = 0;
- Reallocate(size);
- }
-
- DArray(const DArray& inCopyThis)
- {
- _a = NEW T[inCopyThis._size];
- if(_a != NULL){
- _size = inCopyThis._size;
- for(UInt32 z = 0;z<_size;z++){
- _a[z] = inCopyThis._a[z];
- }
- }
- }
-
- ~DArray()
- {
- delete [] _a;
- }
-
- OSErr Reallocate(UInt32 size)
- {
- delete [] _a;
- _a = NEW T[size];
- if(_a == NULL){
- _size = 0;
- return -108;
- }else{
- _size = size;
- return noErr;
- }
- }
-
- void SetSize(UInt32 newSize) // only use for shortening the list
- {
- _size = newSize;
- }
-
- DArray& operator =(const DArray& inCopyThis)
- {
- delete [] _a;
- _size = 0;
- _a = NEW T[inCopyThis._size];
- if(_a != NULL){
- _size = inCopyThis._size;
- for(UInt32 z = 0;z<_size;z++){
- _a[z] = inCopyThis._a[z];
- }
- }
-
- return *this;
- }
-
- T& operator[](int index)
- {
- return *(_a + index);
- }
-
- const T& operator[](int index) const
- {
- return *(_a + index);
- }
-
- UInt32 Size() const
- {
- return _size;
- }
-
- operator T*()
- {
- return _a;
- }
-
-
- private:
-
- T* _a;
- UInt32 _size;
- };
-
-
-
-
- #endif
-
-